package com.lc.ibps.platform.rest.org;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.lc.ibps.api.org.service.IPartyRelService;
import com.lc.ibps.base.core.util.AppUtil;
import com.lc.ibps.cloud.entity.APIResult;
import com.lc.ibps.web.controller.BaseApiController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 * 参与者关系服务 控制器，第三方系统调用。
 *
 * <pre>
 *  
 * 构建组：ibps-platform-webapi
 * 作者：eddy
 * 邮箱：1546077710@qq.com
 * 日期：2016年9月22日-下午2:47:07
 * 版权：广州流辰信息技术有限公司版权所有
 * </pre>
 */
@RequestMapping(value = "/api/webapi/relService")
@Api(value = "/relService", tags = "用户管理-参与者关系服务")
@RestController
public class RelController extends BaseApiController{

	private IPartyRelService relService;

	public RelController() {
		relService = AppUtil.getBean(IPartyRelService.class);
	}

	@ApiOperation(value = "获取参与者关系类型列表", notes = "获取参与者关系类型列表")
	@RequestMapping(value = "/findPartyRelations", method = RequestMethod.GET)
	public APIResult<String> findPartyRelations(
			@ApiParam(value = "partyType", required = true) @RequestParam(name = "partyType", required = true) String partyType) {
		APIResult<String> result = new APIResult<>();
		try {
			String rel = relService.getPartyRelationsJson(partyType);
			result.setData(rel);
		} catch (Exception e) {
			result = getExceptionResult(result, ERROR, "获取参与者关系类型列表失败！", e);
		}

		return result;
	}

	@ApiOperation(value = "获取角色关系类型列表", notes = "获取角色关系类型列表")
	@RequestMapping(value = "/findRoleRelations", method = RequestMethod.GET)
	public APIResult<String> findRoleRelations() {
		APIResult<String> result = new APIResult<>();
		try {
			String rel = relService.getRoleRelationsJson();
			result.setData(rel);
		} catch (Exception e) {
			result = getExceptionResult(result, ERROR, "获取角色关系类型列表失败！", e);
		}

		return result;
	}

	@ApiOperation(value = "获取用户关系类型列表", notes = "获取用户关系类型列表")
	@RequestMapping(value = "/findUserRelations", method = RequestMethod.GET)
	public APIResult<String> findUserRelations() {
		APIResult<String> result = new APIResult<>();
		try {
			String rel = relService.getUserRelationsJson();
			result.setData(rel);
		} catch (Exception e) {
			result = getExceptionResult(result, ERROR, "获取用户关系类型列表失败！", e);
		}

		return result;
	}

	@ApiOperation(value = "获取用户与参与者关系类型列表", notes = "获取用户与参与者关系类型列表")
	@RequestMapping(value = "/findUserPartyRelations", method = RequestMethod.GET)
	public APIResult<String> findUserPartyRelations(
			@ApiParam(value = "partyType", required = true) @RequestParam(name = "partyType", required = true) String partyType) {
		APIResult<String> result = new APIResult<>();
		try {
			String rel = relService.getUserPartyRelationsJson(partyType);
			result.setData(rel);
		} catch (Exception e) {
			result = getExceptionResult(result, ERROR, "获取用户与参与者关系类型列表失败！", e);
		}
		return result;
	}

	@ApiOperation(value = "获取用户与角色关系类型列表", notes = "获取用户与角色关系类型列表")
	@RequestMapping(value = "/findUserRoleRelations", method = RequestMethod.GET)
	public APIResult<String> findUserRoleRelations() {
		APIResult<String> result = new APIResult<>();
		try {
			String rel = relService.getUserRoleRelationsJson();
			result.setData(rel);
		} catch (Exception e) {
			result = getExceptionResult(result, ERROR, "获取用户与角色关系类型列表失败！", e);
		}
		return result;
	}

}
